include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckFunctionExists)
include(CheckTypeSize)
include(CheckStructExists)

check_include_files(lzma.h HAVE_LZMA_H)
check_include_files(bzlib.h HAVE_BZLIB_H)
check_include_files(zlib.h HAVE_ZLIB_H)
check_include_files(pthread.h HAVE_PTHREAD_H)

find_library(HAVE_LZMA_L lzma)
find_library(HAVE_BZLIB_L bz2)
find_library(HAVE_ZLIB_L z)
find_library(HAVE_PTHREAD_L pthread)

set(CMAKE_EXTA_INCLUDE_FILES sys/types.h)
check_type_size("off_t" OFFT_SIZE)
check_type_size("off64_t" OFF64T_SIZE)
set(CMAKE_EXTA_INCLUDE_FILES)

set(CMAKE_EXTA_INCLUDE_FILES unistd.h)
check_type_size("ssize_t" SSIZET_SIZE)
check_type_size("size_t" SIZET_SIZE)
set(CMAKE_EXTA_INCLUDE_FILES)

check_struct_exists("struct stat" "sys/types.h;sys/stat.h" HAVE_STAT_R)
check_struct_exists("struct stat64" "sys/types.h;sys/stat.h" HAVE_STAT64_R)

check_symbol_exists(O_LARGEFILE "bits/fcntl.h" HAVE_LARGEFILE_S)
check_function_exists(open64 HAVE_OPEN64_F)
check_function_exists(lseek64 HAVE_LSEEK64_F)
check_function_exists(lstat64 HAVE_LSTAT64_F)

configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

# install header files
install(
	FILES yar.h
	DESTINATION include
)

# install libyar directory
install(
	DIRECTORY libyar
	DESTINATION include
	FILES_MATCHING PATTERN "*.txt" EXCLUDE
)

add_subdirectory(libyar)